<?php
class makePdf
{
  private $_pdf;

  private $_html;

  private $_subject;

  private $_title = 'Rioting Nerds Documents';

  /**
   * Init
   */
  public function __construct()
  {
    $this->_pdf = new ETcPdf;
    $this->_pdf->SetAutoPageBreak(false);
  }

  /**
   * set paper size
   *
   * @param string $size
   * @param string $orientation
   */
  public function setSize($size='A4', $orientation='P')
  {
    $this->_pdf->setPageFormat($size, $orientation);
  }

  public function renderPartial($view, $params)
  {
        $html = Yii::app()->controller->renderPartial($view, $params, true, true);
        $this->_pdf->setPrintHeader(false);
        $this->_pdf->setPrintFooter(false);
        $this->_pdf->AddPage();
        $this->_pdf->writeHTML($html, true, false, true, false, '');
  }

  public function stream($name)
  {
        $this->_pdf->SetCreator('RiotingNerds CMS');
        $this->_pdf->SetAuthor('Chris Sim');
        $this->_pdf->SetTitle($this->_title);
        $this->_pdf->SetSubject($this->_subject);
        $this->_pdf->SetKeywords('CMS');
        $this->_pdf->SetFont('helvetica', '', 10);
        $filename = Yii::app()->getBasePath().'/tmp/'. md5(uniqid());
        while (file_exists($filename . '.pdf')) {
            $filename .= rand(10, 99);
        }
        //$this->_pdf->Output($filename.'.pdf','F');
        if(ini_get('zlib.output_compression') == 'On' || ini_get('zlib.output_compression'))
            ini_set('zlib.output_compression', 'Off');
        $this->_pdf->Output($name, 'I');
        return $filename.'.pdf';
  }
}
?>